﻿using System;
using System.Configuration;
using LegoBotPrimaAbstractions.Extensions;

namespace LegoBotPrimaAbstractions
{

    public class Config : ILegoBotPrimaConfig
    {
        public const string Key_AngleDecimalPlaces = "LegoBotPrima.AngleDecimalPlaces";
        public const string Key_ForwardMotion_AverageSpeed = "LegoBotPrima.Key_ForwardMotion_AverageSpeed";
        public const string Key_ForwardMotion_AverageSpeed_Variance = "LegoBotPrima.ForwardMotion_AverageSpeed_Variance";
        public const string Key_MinDistance = "LegoBotPrima.MinDistance";
        public const string Key_LogCallToWorkflow = "LegoBotPrima.LogCallToWorkflow";
        public const string Key_LogPath = "LegoBotPrima.LogPath";
        public const string Key_OpenSpacesPaddingDegrees = "LegoBotPrima.OpenSpacesPaddingDegrees";
        public const string Key_InitialAngle = "LegoBotPrima.InitialAngle";
        public const string Key_MaxNumberPreviousActionsKept = "LegoBotPrima.MaxNumberPreviousActionsKept";
        public const string Key_AccelerometerThreashold = "LegoBotPrima.AccelerometerThreashold";
        public const string Key_MinDistanceBackUpCoeff = "LegoBotPrima.MinDistanceBackUpCoeff";
        public const string Key_MaxSecondsGoingForward = "LegoBotPrima.MaxSecondsGoingForward";
        public const string Key_MaxSecondsRotating = "LegoBotPrima.MaxSecondsRotating";

        private static ILegoBotPrimaConfig _instance = new Config();
        public static ILegoBotPrimaConfig Instance
        {
            get { return _instance; }
            set
            {
                Ensure.IsNotNull(value, "Config.Instance");
                _instance = value;
            }
        }

        public static void ResetDefault()
        {
            _instance = new Config();
        }

        public int AngleDecimalPlaces
        {
            get { return ConfigurationManager.AppSettings[Key_AngleDecimalPlaces].ToIntOrDefault(1); }
        }
        public double ForwardMotion_AverageSpeed
        {
            get { return ConfigurationManager.AppSettings[Key_ForwardMotion_AverageSpeed].ToDoubleOrDefault(13.75); }
        }
        public double ForwardMotion_AverageSpeed_Variance
        {
            get { return ConfigurationManager.AppSettings[Key_ForwardMotion_AverageSpeed_Variance].ToDoubleOrDefault(2.6875); }
        }
        public int MinDistance
        {
            get { return ConfigurationManager.AppSettings[Key_MinDistance].ToIntOrDefault(50); }
        }
        public bool LogCallToWorkflow
        {
            get { return ConfigurationManager.AppSettings[Key_LogCallToWorkflow].ToBooleanOrDefault(false); }
        }
        public string LogPath
        {
            get { return ConfigurationManager.AppSettings[Key_LogPath] ?? "LegoBotPrima/LegoBotPrimaService/WorkfowLog.txt"; }
        }
        public double OpenSpacesPaddingDegrees
        {
            get { return ConfigurationManager.AppSettings[Key_OpenSpacesPaddingDegrees].ToDoubleOrDefault(20.0); }
        }
        public double InitialAngle
        {
            get { return ConfigurationManager.AppSettings[Key_InitialAngle].ToDoubleOrDefault(0.0); }
        }
        public int MaxNumberPreviousActionsKept
        {
            get { return ConfigurationManager.AppSettings[Key_MaxNumberPreviousActionsKept].ToIntOrDefault(100); }
        }
        public double AccelerometerThreashold
        {
            get { return ConfigurationManager.AppSettings[Key_AccelerometerThreashold].ToDoubleOrDefault(20); }
        }
        public double MinDistanceBackUpCoeff
        {
            get { return ConfigurationManager.AppSettings[Key_MinDistanceBackUpCoeff].ToDoubleOrDefault(0.6); }
        }
        public int MaxSecondsGoingForward
        {
            get { return ConfigurationManager.AppSettings[Key_MaxSecondsGoingForward].ToIntOrDefault(30); }
        }
        public int MaxSecondsRotating
        {
            get { return ConfigurationManager.AppSettings[Key_MaxSecondsRotating].ToIntOrDefault(20); }
        }
    }
}
